<?php
use yii\helpers\Url;
use app\data\StaffData;
use yii\bootstrap\ActiveForm;
$this->context->layout=false;

?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<?php 
	$form = ActiveForm::begin([
		'id' => 'm-form',
        'options' => [
        	'class' => 'form-horizontal'
        ]
    ]);
?>
	<div style="margin:15px;">
		
		<div class="panel panel-default">
			<div class="panel-heading">基本资料</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
					<table class="table">
						<tr>
							<th width="20%">
								中文名：
							</th>
							<td width="30%">
								<input type="text" class="k-input k-textbox" name="name_cn_long" >
							</td>
							<th width="20%">
								英文名：
							</th>
							<td width="30%">
								<input type="text" class="k-input k-textbox" name="name_en_long">
							</td>
						</tr>

						<tr>
							<th>
								性别：
							</th>
							<td>
								<input type="text" id="gender_add" name="gender">
							</td>
							<th>
								婚姻状态：
							</th>
							<td>
								<input type="text" id="marital_status_add"  name="marital_status">
							</td>
						</tr>

						<tr>
							<th>
								出生日期：
							</th>
							<td>
								
								<input type="text" id="dob_add" name="dob">
							</td>
							<th>
								民族：
							</th>
							<td>
								<input type="text" class="k-input k-textbox" name="nation" >
							</td>
						</tr>


						<tr>
							<th>
								学历：
							</th>
							<td>
								<input type="text" id="education_add" name="education">
							</td>
							<th>
								毕业学校：
							</th>
							<td>
								<input type="text" class="k-input k-textbox" name="graduation_school" >
							</td>
						</tr>

						<tr>
							<th>
								专业：
							</th>
							<td>
								
								<input type="text" class="k-input k-textbox" name="major" >
							</td>
							<th>
								身份证号码：
							</th>
							<td>
								
								<input type="text" class="k-input k-textbox" name="identity_card_number" >
							</td>
						</tr>

						<tr>
							<th>
								联系电话：
							</th>
							<td>
								
								<input type="text" class="k-input k-textbox" name="phone_number">
							</td>
							<th>
								邮件：
							</th>
							<td>
								
								<input type="text" class="k-input k-textbox" name="email">
							</td>
						</tr>

						<tr>
							<th>
								政治地位：
							</th>
							<td>			
								<input type="text" id="political_status_add" name="political_status">
							</td>
							<th>
								序列号：
							</th>
							<td>
								<input type="text" class="k-input k-textbox" name="serial_number">
							</td>
						</tr>

						<tr>
							<th>
								家庭类型：
							</th>
							<td>
				
								<input type="text" class="k-input k-textbox" name="household_category">					
							</td>
							<th>
								家庭住址：
							</th>
							<td>
								
								<input type="text" class="k-input k-textbox" name="household_location">	
							</td>
						</tr>

						<tr>
							<th>
								银行名称：
							</th>
							<td>
								
								<input type="text" class="k-input k-textbox" name="bank_name">							
							</td>
							<th>
								银行号码：
							</th>
							<td>
								<input type="text" class="k-input k-textbox" name="bank_number">
							</td>
						</tr>

						<tr>
							<th>
								紧急联系人：
							</th>
							<td>
								<input type="text" class="k-input k-textbox" name="emergency_contact">						
							</td>
							<th>
								紧急联系人号码：
							</th>
							<td>
								<input type="text" class="k-input k-textbox" name="emergency_contact_phone_number">
							</td>
						</tr>

						<tr>
							<th>
								地址1：
							</th>
							<td colspan="3">
									
								<input type="text" class="k-input k-textbox" name="address1"  style="width:100%">						
							</td>
							
						</tr>
						<tr>
							<th>
								地址2：
							</th>
							<td colspan="3">
								
								<input type="text" class="k-input k-textbox" name="address2" style="width:100%">
							</td>
						</tr>
						
					</table>
				</div>
			</div>
		</div>
		<br>
		<div class="panel panel-default">
			<div class="panel-heading">职位资料</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
					<table class="table">
						<tr>
							<th width="20%">
								部门名称：
							</th>
							<td width="30%">
								<input type="text"  id="department_id_add" name="department_id">

								<input type="hidden"  id="department_name_add" name="department_name" >
							</td>
							<th width="20%">
								职位：
							</th>
							<td width="30%">
								
								<select id="position_id_add" name="position_id"></select>
								<input type="hidden" id="position_name_add" name="position_name" >
							</td>
						</tr>

						<tr>
							<th>
								组别：
							</th>
							<td>
								
								<select id="group_id_add" name="group_id"></select>
								<input type="hidden" id="group_name_add" name="group_name">
							</td>
							<th>
								在职状态：
							</th>
							<td>

								<input type="text" id="position_status_add" name="position_status">
							</td>
						</tr>


						<tr>
							<th>
								入职日期：
							</th>
							<td>
								<input type="text" id="hired_date_add" name="hired_date">
							</td>
							<th>
								指纹号：
							</th>
							<td>
								
								<input type="text" class="k-input k-textbox" name="finger_print_number">
							</td>
						</tr>

						<tr>
							<th>
								合同状态
							</th>
							<td>
								<input type="text" id="contract_status_add" name="contract_status">
							</td>
							<th>
								工作地点：
							</th>
							<td>
								<input type="text" id="work_place_add" name="work_place" >
							</td>
						</tr>

					</table>
				</div>
			</div>
		</div>
		<Br>
		<div class="panel panel-default">
			<div class="panel-heading">教育经历</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
			  			<a type="button" id="add-education_add" class="k-button k-button-icontext" href="javascript:;"><i class="glyphicon glyphicon-plus"></i>添加</a>
						<div id="education-box_add">

						</div>
					</div>
			  	</div>
			</div>
		</div>

		<br>
		<div class="panel panel-default">
			<div class="panel-heading">员工证书</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
			  			<a type="button" id="add-certificate_add" class="k-button k-button-icontext" href="javascript:;"><i class="glyphicon glyphicon-plus"></i>添加</a>
						<table class="table" id="certificate-table_add" style="margin-top:10px">
							
						</table>
			  	</div>
			</div>
		</div>
		<br>

		<div class="panel panel-default">
			<div class="panel-heading">家庭成员</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
			  			<a type="button" id="add-member_add" class="k-button k-button-icontext" href="javascript:;"><i class="glyphicon glyphicon-plus"></i>添加</a>
						<div id="member-box_add">

						</div>
			  	</div>
			</div>
		</div>
		<br>
		<div class="panel panel-default">
			<div class="panel-heading">工作经验</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
			  			<a type="button" id="add-word_add" class="k-button k-button-icontext" href="javascript:;"><i class="glyphicon glyphicon-plus"></i>添加</a>
						<div id="word-box_add">

						</div>
			  		</div>
				</div>
			</div>
		</div>
		<br>
		<div class="panel panel-default">
			<div class="panel-heading">员工福利</div>
			<div class="panel-body m-panel-body">
			  	<div class="m-box">
			  		<div class="m-box">
						<div id="word-box_add">
							<table class="table">
								<tr>
									<th width="30%">
										停车类型：
									</th>
									<td width="70%">
										<input type="text"  id="add_park_type" name="park_type">
									</td>
								
								</tr>
							</table>
						</div>
			  		</div>
				</div>
			</div>
		</div>

		<a type="button" class="k-button k-button-icontext" id="m-submit_add" href="javascript:;" style="margin-top:20px;float:right;"><i class="glyphicon glyphicon-plus"></i>提交</a>
	</div>
<?php ActiveForm::end(); ?>

<script>

var _contractData = JSON.parse('<?=json_encode(StaffData::getContractStatus()); ?>');
//工作地點
var _workPlaceData = JSON.parse('<?=json_encode(StaffData::getWorkPlace()); ?>');
//在職狀態
var _positionStatusData = JSON.parse('<?=json_encode(StaffData::getPositionStatus()); ?>');
//性別
var _genderData = JSON.parse('<?=json_encode(StaffData::getGender()); ?>');
//婚姻狀態
var _maritalStatusData = JSON.parse('<?=json_encode(StaffData::getMarriage()); ?>');
//學歷
var _educationData = JSON.parse('<?=json_encode(StaffData::getEducation()); ?>');
//政治地位
var _politicalStatusData = JSON.parse('<?=json_encode(StaffData::getPoliticalStatus()); ?>');


$(function(){

	$("#m-submit_add").click(function(){
		var _this=$(this);
		_this.parents("#m-form").ajaxSubmit({
			url : "<?=Url::to(['insert']); ?>",
			dataType:"json",
			success:function(redata){
				if(redata.status==1){
					var _addWindow= addWindow.data('kendoWindow');
				    _addWindow.refresh();
				    _grid.data("kendoGrid").dataSource.read();
				    _grid.data("kendoGrid").refresh();
					_addWindow.close();
				}else{
					layer.msg(redata.info, {icon: 5});
				}
			}
		})
	})

    $.ajax({
    	url: "<?=Url::toRoute(['/hr/unit/default/getselectall']); ?>",
        dataType: "json",
        type:"GET",
        success:function(redata){
        	var _departmentDataId= new Array;
        	for (var i = 0; i < redata.length ; i++) {
        		_departmentDataId[i]=redata[i].value;
        	}
        	//单选控件
			$("#department_id_add").kendoDropDownList({
		        dataTextField: "text",
		        dataValueField: "value",
		        dataSource: redata,
		        index:-1,
		        change:function(e){
		        	var _id = $("#department_id_add").data("kendoDropDownList").value();
		        	setGroup(_id);
		        	setPosition(_id);
		        }
		    })
		    //设置组别
		    setGroup("");
		    setPosition("");
        }
    })

    $("#add_park_type").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource:JSON.parse('<?=json_encode(StaffData::getParkType()) ?>'),
        index:-1
    })

    $("#contract_status_add").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: _contractData,
        index:-1
    })

    $("#work_place_add").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource:_workPlaceData,
        index:-1
    })

    $("#position_status_add").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: _positionStatusData,
        index:-1
    })

    $("#gender_add").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: _genderData,
        index:-1
    })

    $("#marital_status_add").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: _maritalStatusData,
        index:-1
    })

    $("#education_add").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: _educationData,
        index:-1
    })

    $("#political_status_add").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: _politicalStatusData,
        index:-1
    })

    $("#hired_date_add").kendoDatePicker({
    	format:"MM/dd/yyyy"
    });

    $("#dob_add").kendoDatePicker({
    	format:"MM/dd/yyyy"
    });

	$("#add-certificate_add").click(function(e){
		var _guid = guid();
		var _html = '<tr>\
			<th width="16%">\
			<input type="hidden" name="certificate_id[]" />\
				时间：\
			</th>\
			<td width="16%">\
				<input type="text" id='+_guid+' name="certificate_get_date_arr[]" style="width:120px;">\
			</td>\
			<th width="16%">\
				名称：\
			</th>\
			<td width="16%">\
				<input type="text" class="k-input k-textbox" name="certificate_name_arr[]" style="width:120px;">\
			</td>\
			<th width="16%">\
				成绩：\
			</th>\
			<td width="16%">\
				<input type="text" class="k-input k-textbox" name="certificate_result_arr[]" style="width:120px;">\
			</td>\
			<td width="1%">\
				<a href="javascript:;" class="del-row"><i class="glyphicon glyphicon-remove"></i></a>\
			</td>\
		</tr>';

		$("#certificate-table_add").append(_html);

		$("#"+_guid).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

		$(".del-row").click(function(e){
			$(this).parents("tr").remove();
		})

	});

	$("#add-education_add").click(function(e){

		var _startId = guid();

		var _endId = guid();

		var _education = guid();

		var _html = '<div class="row m-table-row" style="margin-top:10px;">\
			&nbsp;&nbsp;\
			<input type="hidden" name="education_id[]" />\
			<div class="label">开始时间</div>\
			&nbsp;&nbsp;\
			<input type="text" id='+_startId+' name="education_start_date_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">结束时间</div>\
			&nbsp;&nbsp;\
			<input type="text" id='+_endId+' name="education_end_date_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">教育机构</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="education_organization_arr[]" style="width:121px;float:left;">\
			<br>\
			<br>\
			&nbsp;&nbsp;\
			<div class="label">专业</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="education_major_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">学历</div>\
			&nbsp;&nbsp;\
			<input type="text" id='+_education+' name="educational_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<a href="javascript:;" class="del-row"><i class="glyphicon glyphicon-remove"></i></a>\
		</div>';

		$("#education-box_add").append(_html);

		$("#"+_startId).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

    	$("#"+_endId).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

    	$("#"+_education).kendoDropDownList({
	        dataTextField: "text",
	        dataValueField: "value",
	        dataSource: JSON.parse('<?=json_encode(StaffData::getEducation()); ?>'),
	      	index:-1
	    })

		$(".del-row").click(function(e){
			$(this).parents(".m-table-row").remove();
		})
	});

	$("#add-member_add").click(function(e){
		var _html = '<div class="row m-table-row" style="margin-top:10px;">\
			&nbsp;&nbsp;\
			<input type="hidden" name="member_id[]" />\
			<div class="label">姓名</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="member_name_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">关系</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="member_relationship_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">工作单位</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="member_work_unit_arr[]" style="width:121px;float:left;">\
			<br>\
			<br>\
			&nbsp;&nbsp;\
			<div class="label">职业</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="member_position_name_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">电话</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="member_tel_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<a href="javascript:;" class="del-row"><i class="glyphicon glyphicon-remove"></i></a>\
		</div>';

		$("#member-box_add").append(_html);

		$(".del-row").click(function(e){
			$(this).parents(".m-table-row").remove();
		})
	})


	$("#add-word_add").click(function(e){
		var _startId = guid();

		var _endId = guid();

		var _html = '<div class="row m-table-row" style="margin-top:10px;">\
			&nbsp;&nbsp;\
			<input type="hidden" name="word_id[]" />\
			<div class="label">开始时间</div>\
			&nbsp;&nbsp;\
			<input type="text" id='+_startId+' name="word_start_date_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">结束时间</div>\
			&nbsp;&nbsp;\
			<input type="text" id='+_endId+' name="word_end_date_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">单位名称</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="word_unit_name_arr[]" style="width:121px;float:left;">\
			<br>\
			<br>\
			&nbsp;&nbsp;\
			<div class="label">职位</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="word_position_name_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<div class="label">离职原因</div>\
			&nbsp;&nbsp;\
			<input type="text" class="k-input k-textbox" name="word_leave_reason_arr[]" style="width:121px;float:left;">\
			&nbsp;&nbsp;\
			<a href="javascript:;" class="del-row"><i class="glyphicon glyphicon-remove"></i></a>\
		</div>';


		$("#word-box_add").append(_html);

		$("#"+_startId).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

    	$("#"+_endId).kendoDatePicker({
    		format:"MM/dd/yyyy"
    	})

		$(".del-row").click(function(e){
			$(this).parents(".m-table-row").remove();
		})
	})
})


function setGroup(_unitId,_bIndex){
	$.ajax({
		url: "<?=Url::toRoute(['/hr/unit/default/getselectall']); ?>",
        dataType: "json",
        type:"GET",
        data:{unit_id:_unitId,type:2},
        success:function(redata){

        	$("#group_id_add").kendoDropDownList({
		        dataTextField: "text",
		        dataValueField: "value",
		        dataSource: redata,
		        change:function(e){
		        	var _value = $("#group_id_add").data("kendoDropDownList").text();
		        	$("#group_name_add").val(_value);
		        } 
		    });
        	var dropdownlist = $("#group_id_add").data("kendoDropDownList");

        	dropdownlist.select(-1);

		    dropdownlist.refresh();
        }
	})
}

function setPosition(_unitId,_bIndex){
	$.ajax({
		url: "<?=Url::toRoute(['/hr/position/default/getselectallbyunitid']); ?>",
        dataType: "json",
        type:"GET",
        data:{unit_id:_unitId},
        success:function(redata){
        
    
    		$("#position_id_add").kendoDropDownList({
		        dataTextField: "text",
		        dataValueField: "value",
		        dataSource: redata,
		        change:function(e){
		        	var _value = $("#position_id_add").data("kendoDropDownList").text();
		        	$("#position_name_add").val(_value);
		        } 
		    })
        	var dropdownlist = $("#position_id_add").data("kendoDropDownList");

        	dropdownlist.select(-1);

		    dropdownlist.refresh();
        }
	})
}

function guid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
        return v.toString(16);
    });
}


</script>